String clazzTpl({package}) => """
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:$package/utils/print_util.dart';

/// 请叫我code哥
/// Generates Dart code
class LogInterceptors extends InterceptorsWrapper {
  @override
  void onRequest(
      RequestOptions options, RequestInterceptorHandler handler) async {
    Map<String, dynamic> header = {
      'host': options.baseUrl,
      'url': options.path,
    };
    if (options.headers.isNotEmpty) {
      header['headers'] = options.headers;
    }
    if (options.queryParameters.isNotEmpty) {
      header['queryParams'] = options.queryParameters;
    }
    if (options.data != null) {
      header['body'] = options.data;
    }
    logDebugPrint(LogInterceptors.formatJson(jsonEncode(header),
        tag: 'request', isJsonString: true));
    handler.next(options);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) async {
    logDebugPrint(LogInterceptors.formatJson(response.toString(),
        tag: 'response', isJsonString: true));
    handler.next(response);
  }

  @override
  void onError(DioError err, ErrorInterceptorHandler handler) async {
    var error = {
      'err': err.toString(),
      'requestInfo': err.requestOptions.toString(),
      'responseInfo': err.response?.toString() ?? "",
    };
    logDebugPrint(LogInterceptors.formatJson(error.toString(),
        tag: 'error', isJsonString: false));
    handler.next(err);
  }

  static String formatJson(String json,
      {String tag = 'xxxx', bool isJsonString = true}) {
    if (json.isEmpty) return "";
    StringBuffer sb = StringBuffer();
    int lengthW = 80;
    for (int i = 0; i < lengthW; i++) {
      if (i == 0) sb.write('╔');
      sb.write('═');
    }
    sb.write('\\n');
    sb.write('║ ' + 'TAG:' + tag);
    sb.write('\\n');
    String last = '';
    String current = '';
    int indent = 0;
    for (int i = 0; i < json.length; i++) {
      last = current;
      current = json[i];
      switch (current) {
        case '{':
        case '[':
          if (i == 0) sb.write('║ ');
          sb.write(current);
          sb.write('\\n');
          indent++;
          _indent(sb, indent);
          break;
        case '}':
        case ']':
          sb.write('\\n');
          if (i == json.length - 1) {
            sb.write('║ ');
          }
          indent--;
          _indent(sb, indent);
          sb.write(current);
          break;
        case ',':
          sb.write(current);
          if (isJsonString) {
            if (last != '' && (json[i + 1] == '"' || json[i + 1] == '{')) {
              sb.write('\\n');
              _indent(sb, indent);
            }
          } else {
            if (last != '') {
              sb.write('\\n');
              _indent(sb, indent);
            }
          }
          break;
        default:
          sb.write(current);
      }
    }
    sb.write('\\n');
    for (int i = 0; i < lengthW; i++) {
      if (i == 0) sb.write('╚');
      sb.write('═');
    }
    return sb.toString();
  }

  static void _indent(StringBuffer sb, int number) {
    for (int i = 0; i < number; i++) {
      if (i == 0) sb.write('║ ');
      sb.write('\\t');
    }
  }
}
""";
